<template>
	<view class="container">
		<view class="bac"></view>
		<uniNavBar name="考题" nextFlag="flase" rightText="flase" bac="trans"></uniNavBar>
		<view class="content">
			<view class="title-flex">
				<view>单项选择题</view>
				<view>
					<text>{{ selIndex }}/{{ list.length }}</text>
				</view>
			</view>

			<view class="uli">
				<view class="name">{{ list[selIndex - 1].ask }}：</view>
				<view class="radio">
					<view class="radio-li" v-for="(item, idx) in list[selIndex - 1].answer" @click="select(idx)" :key="idx">
						<view>
							<text :class="sel[selIndex - 1] == idx ? 'after' : ''" >{{t_ind[idx]}}</text>
							{{ item.name }}
							<image src="../../static/success.png" v-if="item.success" mode=""></image>
							<image src="../../static/fail.png" v-if="item.fail" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-tar" @click="next(0)" v-if="submitFlag">交卷并查看结果</view>
		<view class="bottom-tar" @click="next(1)" v-else>下一题</view>
	</view>
</template>

<script>
import { activityList, post } from '@/utils/interface.js';
export default {
	data() {
		return {
			sel: [],
			list: [],
			selIndex: 1,
			correct: [],
			submitFlag: false,
			id: '',
			bok:true,
			p_index:0,
			t_ind:["A","B","C","D","E","F","G","H","I","J","k"]
		};
	},
	methods: {
		details(index) {
			
			if (index == 0) {
				uni.navigateTo({
					url: '/pages/me/study-details'
				});
			} else {
				uni.navigateTo({
					url: '/pages/me/paper'
				});
			}
		},
		next(index) {
			this.bok = false
			if (index == 0) {
				this.bok = true
				uni.navigateTo({
					url: '/pages/me/paper-answer?id=' + this.id + '&correct=' + this.correct
				});
			} else {
				
				if (this.selIndex != this.correct.length) {
					uni.showToast({
						title: '请选择',
						icon: 'none'
					});
					return false;
				}
				console.log(this.sel)
				if(this.p_index == this.list[this.selIndex - 1].correct){
					this.list[this.selIndex - 1].answer[this.p_index].success = true
				}else{
					console.log(this.list[this.selIndex - 1])
					this.list[this.selIndex - 1].answer[this.p_index].fail = true
					this.list[this.selIndex - 1].answer[this.list[this.selIndex - 1].correct].success = true
				}
				setTimeout(()=>{
					this.bok = true
					this.selIndex = parseInt(this.selIndex) + 1;
					console.log(this.selIndex)
					if (this.selIndex == this.list.length) {
						this.submitFlag = true;
					}
				},1000)
			}
		},
		select(idx) {
			if(!this.bok){
				return false
			}
			
			this.sel[this.selIndex - 1] = idx;
			this.p_index = idx
			console.log(this.p_index);
			this.$set(this.sel, this.selIndex - 1, idx);
			if (this.sel[this.selIndex - 1] == this.list[this.selIndex - 1].correct) {
				this.correct[this.selIndex - 1] = true;
			} else {
				this.correct[this.selIndex - 1] = false;
			}
			
		},
		getlist(id) {
			console.log(id);
			activityList({ method: 'activities.task_ask', task_id: id, token: uni.getStorageSync('userToken') }).then(res => {
				console.log(res.data);
				if (res.status == false) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					return false;
				}
				res.data.map(item=>{
					let obj=[]
					item.answer.map(item=>{
						obj.push({name:item,success:false,fail:false})
						
					})
					item.answer = obj
				})
				console.log(res.data)
				this.list = res.data;
				
			});
		}
	},
	onLoad(options) {
		this.id = options.taskId;
		this.selIndex = 1;
		this.getlist(options.taskId);
	}
};
</script>

<style>
.title-flex {
	display: flex;
	align-items: center;
}
.container {
}
.bac {
	/* position:absolute;

		top: 0; */
	height: 400upx;
	/* left: 0;
		right: 0; */
	/* border-bottom-right-radius: 100%;
		border-bottom-left-radius: 100%; */

	background: #4ccfa6;
	z-index: -1;
}
.content {
	width: 710upx;
	position: absolute;
	top: 50upx;
	left: 20upx;
}
.uli {
	width: 670upx;
	min-height: 400upx;
	box-shadow: 0 0 10upx #dddddd;
	background: #ffffff;
	border-radius: 20upx;
	margin-top: 30upx;
}
.title-flex {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 80upx;
}
.title-flex view:nth-of-type(1) {
	color: #ffffff;
}
.title-flex view:nth-of-type(2) {
	display: flex;
	align-items: center;
}
.title-flex view:nth-of-type(2) text {
	background: rgba(0, 0, 0, 0.1);
	color: #ffffff;
	border-radius: 20upx;
	font-size: 20upx;
	padding: 6upx 30upx;
}
.name {
	line-height: 100upx;
	font-size: 30upx;
	font-weight: bold;
}
.uli {
	padding: 0 20upx;
}

.radio-li {
	height: 60upx;
	line-height: 60upx;
	display: flex;
	align-items: center;
	font-size: 28upx;
}
.radio-li view {
	display: flex;
	align-items: center;
}
.radio-li view text {
	margin-right: 20upx;
	width: 40upx;
	height: 40upx;
	border-radius: 100%;
	line-height: 40upx;
	text-align: center;
	border: 1px solid #4ccfa6;
	color: #4ccfa6;
	font-size: 20upx;
	display: block;
}
.radio-li view .after {
	background: #4ccfa6;
	color: #ffffff;
}
.radio-li view image{
	display: block;
	width: 30upx;
	height: 30upx;
}
.bottom-tar {
	position: fixed;
	bottom: 20upx;
	left: 20upx;
	width: 710upx;
	border-radius: 20upx;
	height: 80upx;
	line-height: 80upx;
	color: #ffffff;
	background: #4ccfa6;
	text-align: center;
	font-size: 24upx;
}
</style>
